package com.meet.util;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * 时间的转换类
 * @author admin
 *
 */
public class DateUtil {

    public static Date getCurrentTime(){
        String currenttime= LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        //Date date=new Date();
        Date date=string3Date(currenttime);
        return date;
    }

    private static SimpleDateFormat sdf3=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


    public static Date convertDateTo3Date(Date date){
        //SimpleDateFormat date1= (SimpleDateFormat)date;
        return date;
    }

    //将字符串格式为 "yyyy-MM-dd HH:mm:ss"转化成时间类型 Date
    public static Date string3Date(String dateString)
    {
        Date date=null;
        try {
            date=sdf3.parse(dateString);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return date;
    }
    //将时间类型转化成字符串 格式为 "yyyy-MM-dd HH:mm:ss"
    public static String TimestampToString(Timestamp timestamp)
    {
        System.out.println(timestamp.toString());
        String timeStr=timestamp.toString();
        /*int index=timeStr.lastIndexOf(":");
        int length=timeStr.length();
        System.out.println(index);
        System.out.println(length);*/
       // System.out.println(timeStr.substring(0,timeStr.lastIndexOf(":")+3));
        String timeString=timeStr.substring(0,timeStr.lastIndexOf(":")+3);
       // System.out.println(timeString);
        return timeString;
    }


}